//
//  EGDetailView.m
//  Orchard
//
//  Created by 黄勇锋 on 16/8/21.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "EGDetailView.h"

@interface EGDetailView()



@end


@implementation EGDetailView



- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
    
        //设置属性
        [self setupUI];
        
        self.count = 0;
    }
    
    return self;
}



- (void)setupUI{
    
    //添加控件
    [self addSubview:self.nameLabel];
    [self addSubview:self.selectedLabel];
    [self addSubview:self.weightLabel];
    [self addSubview:self.currentPriceLabel];
    [self addSubview:self.prePriceLabel];
    
    [self addSubview:self.increaseButton];
    [self addSubview:self.reduceButton];
    
    [self addSubview:self.countLabel];
    
    //设置约束
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.equalTo(self);
//        make.width.equalTo(self.frame.size.width);
        
    }];
    
    [self.countLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.increaseButton);
        make.right.equalTo(self).offset(-43);
    }];

    
    [self.increaseButton makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self).offset(-8);
        make.bottom.equalTo(self).offset(-5);
    }];

    [self.reduceButton makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.increaseButton);
        make.right.equalTo(self.increaseButton.left).offset(-25);
        
    }];

    
    
    [self.selectedLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.nameLabel).offset(5);
        make.top.equalTo(self.nameLabel.mas_bottom);
    }];
    
    [self.weightLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.nameLabel);
        make.top.equalTo(self.selectedLabel.mas_bottom);
    }];
    
    [self.currentPriceLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.nameLabel);
        make.top.equalTo(self.weightLabel.mas_bottom);
    }];

    [self.prePriceLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.currentPriceLabel);
        make.left.equalTo(self.currentPriceLabel.mas_right).offset(8);
    }];

    
}

- (UILabel *)nameLabel{
    
    if (_nameLabel == nil) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.text = @"爱蜂蜜-蜜桔";
        _nameLabel.font = [UIFont systemFontOfSize:14];
        _nameLabel.textColor = [UIColor blackColor];
        
        _nameLabel.textAlignment = NSTextAlignmentRight;
    }
    return _nameLabel;
}

- (UILabel *)selectedLabel {
    
    if (_selectedLabel == nil) {
        _selectedLabel = [[UILabel alloc]init];
        _selectedLabel.text = @"精选 买一送一";
        _selectedLabel.font = [UIFont systemFontOfSize:12];
        _selectedLabel.textAlignment = NSTextAlignmentRight;
    }
    
    return _selectedLabel;
}

- (UILabel *)weightLabel{
    
    if (_weightLabel == nil) {
        _weightLabel = [[UILabel alloc]init];
        _weightLabel.text = @"450g/盒";
        _weightLabel.textColor = [UIColor darkGrayColor];
        _weightLabel.font = [UIFont systemFontOfSize:14];
        
    }
    return _weightLabel;
}

- (UILabel *)currentPriceLabel{
    
    if (_currentPriceLabel == nil) {
        _currentPriceLabel = [[UILabel alloc]init];
        
        _currentPriceLabel.text = @"$7.9";
        _currentPriceLabel.font = [UIFont systemFontOfSize:14];
        _currentPriceLabel.textColor = [UIColor redColor];
    }
    
    return _currentPriceLabel;
}

- (UILabel *)prePriceLabel{
    
    if (_prePriceLabel == nil) {
        _prePriceLabel = [[UILabel alloc]init];
        
        _prePriceLabel.font = [UIFont systemFontOfSize:14];
    
        _prePriceLabel.textColor = [UIColor darkGrayColor];
    }
    
    return _prePriceLabel;
}

#pragma mark - 购物动画
- (UIButton *)increaseButton{
    
    if (_increaseButton == nil) {
        _increaseButton = [[UIButton alloc]init];
        
        [_increaseButton setImage:[UIImage imageNamed:@"v2_increase"] forState:UIControlStateNormal];
        
        [_increaseButton sizeToFit];
        
    }
    return _increaseButton;
}


- (UIButton *)reduceButton{
    
    if (_reduceButton == nil) {
        _reduceButton = [[UIButton alloc]init];
        
        [_reduceButton setImage:[UIImage imageNamed:@"v2_reduce"] forState:UIControlStateNormal];
        
    }
    
    return _reduceButton;
}

- (UILabel *)countLabel{
    
    if (_countLabel == nil) {
        _countLabel = [[UILabel alloc]init];
        
        _countLabel.text = [NSString stringWithFormat:@"%ld",self.count];
    }
    
    return _countLabel;
}


@end
